<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h2>开灯</h2>
    <script>
        // 电器
        function Device(){
            this.ford='220v';
            this.efficiency='一级';
        }
        // 开灯
        Device.prototype.open=()=>{
            console.log('灯开了');
        }
        // 关灯
        Device.prototype.close=()=>{
            console.log('灯关了');
        }
        // 实例化对象 灯
        let Lamp=new Device();
        Lamp.color='白色';
        console.log(Lamp);
        let h2=document.querySelector('h2');
        h2.onclick=function(){
            if(this.textContent=="开灯"){
                this.textContent="关灯";
                Lamp.open();
            }else{
                this.textContent="开灯";
                Lamp.close();
            }
        }
    </script>
</body>
</html>